package com.zql.JianZhiOffer;

/**
 * 替换空格
 * Created By ShuHua on 2022/5/3.
 */
public class Offer_05 {
    /**
     * 使用StringBuilder拼接
     * @param s
     * @return
     */
    public static String replaceSpace(String s) {
        StringBuilder res = new StringBuilder();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if(chars[i]==' '){
                res.append("%20");
                continue;
            }
            res.append(chars[i]);
        }
        return res.toString();
    }
    public static String replaceSpace2(String s) {

        return s.replace(" ","%20");
    }


    public static void main(String[] args) {
        String s= "We are happy.";
        System.out.println(replaceSpace2(s));
    }
}
